class Solution:
    def firstUniqChar(self, s: str) -> str:
        # Python 3.6 之后, 字典默认是有序的
        dic = {}

        for i in s:
            dic[i] = not i in dic

        # 直接迭代空字典也不会报错, 所以不用提前检查字符串是否为空字符串
        for k, v in dic.items():
            if v: return k

        return " "

# 上面的操作直接让空间复杂度变成了 O(1), 因为只有 26 个英文字母, 空间复杂度为 O(26) = O(1)
# 时间复杂度还是 O(N)

if __name__ == '__main__':
    solution = Solution()

    s = "abaccdeff"
    print(f"First Unique Char: {solution.firstUniqChar(s)}")

    s = ""
    print(f"First Unique Char: {solution.firstUniqChar(s)}")
    